// 教师数据访问层
package org.example.backend.repository;

import org.example.backend.entity.Teacher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Optional;

@Repository
public interface TeacherRepository extends JpaRepository<Teacher, Long> {
    Optional<Teacher> findByUserId(Long userId);
    Optional<Teacher> findByTeacherNumber(String teacherNumber);

    @Query("SELECT t FROM Teacher t WHERE " +
            "(:name IS NULL OR t.name LIKE %:name%) AND " +
            "(:teacherNumber IS NULL OR t.teacherNumber LIKE %:teacherNumber%) AND " +
            "(:department IS NULL OR t.department LIKE %:department%)")
    Page<Teacher> findByConditions(@Param("name") String name,
                                   @Param("teacherNumber") String teacherNumber,
                                   @Param("department") String department,
                                   Pageable pageable);

}
